/*
 * =======================================================================================变量定义区
 */
var params=new Array;//参数数组
var surveyId="";//问卷id
var surveyName="";//问卷名称
var status="";//问卷状态
var emails="";//邮件列表
var title="";//邮件内容
var copyswf = BASE_PATH+"/res/js/thirdParty/jquery.zclip/ZeroClipboard.swf";//swf文件路径
/*
 * =======================================================================================页面初始化函数
 */
$(function()
{
	//判断是否安装了flash插件
	var fls=flashChecker(); 
	
	//安装flash插件
	if(!fls.f)
	{  
	    if(confirm("您的浏览器还没有安装Flash插件，现在安装？"))
	    {  
	        window.location.href = BASE_PATH+"/media/install_flash_player_20_plugin.exe";  
	    }  
	}
	
	//获得收件人邮箱列表
	getEmailData();

	//标题复制
	$("#copyTitle").zclip(
	{
		path: copyswf,
		copy: function()
		{
			return switchHtmlReverse(title);
		}
	});
	//内容复制
	$("#copyContent").zclip(
	{
		path: copyswf,
		copy: function()
		{
			return switchHtmlReverse($("#content").text());
		}	
	});
});

/*
 * =======================================================================================函数定义区
 */
//获取邮件数据
function getEmailData()
{
	//邮件内容
	var content="";
	//获取参数
	params=window.dialogArguments;
	surveyId=params[0];
	surveyName=switcHtml(params[1]);
	status=params[2];
	if(status=='1')
	{   
		title = "["+surveyName +"]问卷 投票邀请";
		content="请对["+surveyName+"]问卷进行投票，投票系统地址为：XXX,用户名为mysingle账号，初始密码为123456";
		$("#surveyName").html(title);
		$("#content").html(content);
	}else{
		title = "["+surveyName+"]问卷 查看投票结果";
		content="["+surveyName+"]问卷已经投票完成，可登陆XXX查看投票结果,用户名为mysingle账号，初始密码为123456";
		$("#surveyName").html(title);
		$("#content").html(content);
	}
	$.ajax(
	{
		type:'post',
		url :BASE_PATH+"/survey/surveyManagement/surveyEmail/getEmailData.do",
		dateType:"json",
		data:
		{
			"surveyId":surveyId,
			"status"  :status,
			"query_condition_field_list":"surveyId,status"
		},
		cache:false,
		success:function(data)
		{
			var html ="";        	
        	var queryResult = data;
        	if(queryResult!=null&&queryResult!=undefined&&queryResult.length>0)
        	{
        		
        		html = '<ul>';
        		$.each(queryResult,function(i,n)
        	    {	
        	    	 var cnName=switcHtml(n.cnName);
        	    	 cnName = cnName.replace(/ /g, "&nbsp;");  
        	    	 var email =switcHtml(n.email);
        	    	 email = email.replace(/ /g, "&nbsp;");
        	    	 html += '<li>'+cnName+'/'+email+'</li>';
        	    	 emails += email+';';
        	    });
        		html += '</ul>';
        		$("#recipient").html(html);
        		$("#copyEmail").css('display','block'); 
;
        		//邮箱复制
        		$("#copyEmail").zclip(
        		{
        			path: copyswf,
        			copy: function()
        			{
        				return emails;
        			}
        		});
        	}
		},
		error:function(e)
		{
			openAlert("加载数据错误");
			return;
		}
	});
}

//关闭按钮事件
function closePopup(){
	window.close();
}

// 判断是否安装了flash插件
function flashChecker()  
{  
	var hasFlash=0;	//是否安装了flash  
	var flashVersion=0;	//flash版本  
  
	if(document.all)  
	{  
		var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');  
		if(swf) 
		{  
			hasFlash=1;  
			VSwf=swf.GetVariable("$version");  
			flashVersion=parseInt(VSwf.split(" ")[1].split(",")[0]);  
		}  
	}else{  
		if (navigator.plugins && navigator.plugins.length > 0)  
		{  
			var swf=navigator.plugins["Shockwave Flash"];  
			if (swf)  
			{  
				hasFlash=1;  
				var words = swf.description.split(" ");  
				for (var i = 0; i < words.length; ++i)  
				{  
					if (isNaN(parseInt(words[i]))) continue;  
					flashVersion = parseInt(words[i]);  
				}  
			}  
		}  
	}  
	return {f:hasFlash,v:flashVersion};  
}  